<?php
//if (isset($_SESSION['username'])) {
include_once 'header_tongji.php';
require_once("../conn.php");
require_once("../change_page.php");
require_once 'common.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" charset= "utf-8 "/>
        <title>乐知家园</title>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #000000;
            }

            .STYLE1 {color: #FFFFFF}
            -->
        </style></head>
    <body>
        <br/>
        <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
            <tr align="align">
                <td bgcolor="#FFFFFF">&nbsp;</td>
                <td bgcolor="#FFFFFF" align="left">&nbsp;</td>
                <td>&nbsp;</td>
                <td bgcolor="#FFFFFF" align="right"><?php
$page_size = 100;
$page = getParameter("page");
if ($page == "") {
    $page = 0;
}
$keyword = getParameter("keyword");
$age_sql_where = "";
$age_sql_and = "";
if ($keyword != "") {
    $sql = "SELECT COUNT(*) AS total FROM t_device WHERE (email LIKE '%" . $keyword . "%' OR nickname LIKE '%" . $keyword . "%')" . $age_sql_and;
} else {
    $sql = "SELECT COUNT(usercode) AS total FROM t_hibaby_title_packet_record " . $age_sql_where;
}

$db = new DBC();
$total_num = $db->fetchData($sql);
if ($total_num != null) {
    $total_num_product = $total_num[0]['total'];
}
$page_count = getPageSize($total_num_product, $page_size);
echo getPage("tongji_yonghu_titlePacket.php?menu=tongji_yonghu_titlePacket", $page_count, $page);
?></td>
            </tr>
        </table>
        <br/>
        <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#9999FF">
            <tr align="center">
                <td bgcolor="#666666"><span class="STYLE1">序号</span></td>
                <td bgcolor="#666666"><span class="STYLE1">用户UID</span></td>
                <td bgcolor="#666666" colspan="2"><span class="STYLE1">基础题包</span></td>
                <td bgcolor="#666666" colspan="2"><span class="STYLE1">音乐题包</span></td>
                <td bgcolor="#666666" colspan="2"><span class="STYLE1">动画题包</span></td>                
            </tr>
            <?php
            $begin = $page * $page_size;
            if ($keyword != "") {
                $sql = "SELECT * FROM t_device WHERE (nickname LIKE '%" . $keyword . "%' OR email LIKE '%" . $keyword . "%') " . $age_sql_and . " ORDER BY deviceid LIMIT " . $begin . "," . $page_size;
            } else {
//                $sql = "SELECT * FROM t_hibaby_title_packet_record " . $age_sql_where . " ORDER BY deviceid LIMIT " . $begin . "," . $page_size;
                $sql = "SELECT usercode,titlecode,createTime,type FROM t_hibaby_title_packet_record group by usercode,titlecode ORDER BY createTime DESC LIMIT " . $begin . "," . $page_size;
            }
            $num = $begin;
            $data = $db->fetchData($sql);
            $array = array();
            foreach ($data as $product) {
                $usercode = $product['usercode'];
                if ($product['titlecode'] == "Pnomal") {
                    $array[$usercode][0] = $product['createTime'];
                    $array[$usercode][1] = $product['type'];
                } else if ($product['titlecode'] == "Pmusic") {
                    $array[$usercode][2] = $product['createTime'];
                    $array[$usercode][3] = $product['type'];
                } else if ($product['titlecode'] == "Panimal") {
                    $array[$usercode][4] = $product['createTime'];
                    $array[$usercode][5] = $product['type'];
                }
            }
            foreach ($array as $key => $product) {
                $usercode = $key;
                if (strlen($usercode) > 6) {
                    $usercode = substr($usercode, 0, 6);
                }
                for ($i = 0; $i < 6; $i++) {
                    if (!isset($product[$i])) {
                        $product[$i] = "";
                    }
                }
                ?>
                <tr>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo++$num; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $usercode; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product[0]; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product[1]; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product[2]; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product[3]; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product[4]; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product[5]; ?></td>
                </tr>
            <?php } ?>
        </table>
    </body>
</html>
<?php
include_once '../footer.php';
//} else {
//    header("login.php");
//}
?>